<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    :confirm-loading="loading"
    cancelText="关闭">
   <!-- <base-settlement-org-user-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :confirmLoading="confirmLoading"></base-settlement-org-user-form>  -->
    <a-spin :spinning="confirmLoading">
    <div v-if="model.authStatus=='3'" class="revisedContent">驳回原因：{{model.refuseReason}} </div>
    <h3 class="title">基本信息</h3>
     <a-form-model>
    <a-form-model-item label="认证类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="authType">
        <a-radio-group v-model="authType" @change="onChangeAuthType">
                <a-radio value="0" :disabled="initAuthType=='1'?true:false">个人认证</a-radio>
                <a-radio value="1">企业认证</a-radio>
              </a-radio-group>               
      </a-form-model-item>
      </a-form-model>
    <base-settle-org-personal-auth v-if="authType=='0'" ref="BaseSettleOrgPersonalAuth" :model="model" @ok="submitCallback" @loadingCallback="loadingCallback"></base-settle-org-personal-auth>
    <base-settlement-company-auth v-if="authType=='1'" ref="BaseSettlementCompanyAuth" :companyModel="companyModel" @ok="submitCallback" @loadingCallback="loadingCallback"></base-settlement-company-auth>
  </a-spin>
  </j-modal>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
// import BaseSettleOrgPersonalAuth from '../modules/BaseSettlementOrgUserForm.vue'
import BaseSettlementCompanyAuth from '../modules/BaseSettlementCompanyAuth.vue'
import BaseSettleOrgPersonalAuth from '../BaseSettleOrgPersonalAuth.vue'
  export default {
    name: 'BaseSettlementOrgUserModal',
    components: {BaseSettlementCompanyAuth, BaseSettleOrgPersonalAuth},
    data () {
      return {
        title:'',
        width:950,
        visible: false,
        disableSubmit: false,
        confirmLoading:false,
        loading:false,
        authType:'0',
        model: {
         authType:'0',
         orgName:'',
       },
      companyModel:{
        authType:'1',
        izSamePerson:'1',  
      },
      initAuthType:'0',
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      labelColIdCard: {
        xs: { span: 24 },
        sm: { span: 10 },
      },
      wrapperColIdCard: {
        xs: { span: 24 },
        sm: { span: 14 },
      },
      url: {
        // add: '/finance/baseSettlementOrgUser/add',
        commit: '/finance/baseSettlementOrgAuth/commit',
        queryById: '/finance/baseSettlementOrgAuth/queryById',  //通过id查询组织认证信息
      },
      }
    },
    methods: {
      add () {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.add();
        })
      },
      edit (record) {
        this.visible=true
        // this.$nextTick(()=>{
        //   this.$refs.realForm.edit(record);
        // })
        this.getBaseSettlementOrgAuth(record)
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
         //获取认证信息
    getBaseSettlementOrgAuth(record){
      const that=this
      getAction(that.url.queryById, {id: record.id})
         .then(res=>{         
          if(res.success){
            res.result.authType=res.result.authType?res.result.authType:'0'
            that.authType=res.result.authType
            that.model.authStatus=res.result.authStatus
            that.model.refuseReason=res.result.refuseReason
            if(that.authType=='0'){
               that.model=res.result
               that.model.orgName=record.name
            }else{
              that.companyModel =res.result
              that.companyModel.orgName=record.name
            }
             that.initAuthType=res.result.authType?res.result.authType:'0'
          }else{
            that.$message.warning(res.result)
          }
         })
    },
    //切换认证类型
    onChangeAuthType(e){     
      const s=this.model.authType
      const f=e.target.value
      if(e.target.value=='1'){
         this.companyModel ={
            id:this.model.id,
            authType:'1',
            orgName:this.model.orgName,
            izSamePerson:'1',
           }    
      }
    },   
    //
      handleOk () {
        const that = this
      if(that.authType=='0'){
           that.$refs.BaseSettleOrgPersonalAuth.submitForm()
      }else if(that.authType=='1'){
          that.$refs.BaseSettlementCompanyAuth.submitForm()
      }
      },
      loadingCallback(loading){
        this.loading=loading      
      },
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      }
    }
  }
</script>
<style scoped>
.title {
  font-weight: bold;
  margin-left: 3%;
}
.operating {
  padding-right: 30px;
}
.revisedContent {
  margin-bottom: 15px;
  width: 100%;
  background: #fef1e1;
  color: #f59a23;
  padding: 10px 15px;
}

</style>